<?php
/**
* * Model Class
* 
* @author Guillermo Landín
* @link 
* 
* 
*/ 

class Newslettersmodel extends Model {

    function __construct()
    {
        parent::Model();
        
        $this->CI =& get_instance(); 
    }

    
    //returns the list of newsletters
    function get_list(){
    
        $this->db->select('Date_Newsletters, id_Newsletters, Summary_Newsletters, URL_Newsletters, Image_Newsletters')
                ->from('newsletters')
                ->where('Active_Newsletters', 1)
                ->order_by('Date_Newsletters', 'DESC');

        $query = $this->db->get();

        $result = $query->result_array();      
                                 
        return $result;

    }
	
/***********************************
*   Backoffice functions
***********************************/

    //returns the list of news
    function admin_get_list($fields='*'){
    
        $this->db->select($fields)
                ->from('newsletters')
                ->order_by('Date_Newsletters', 'DESC');  

        $query = $this->db->get();

        $result = $query->result_array();
                                 
        return $result;

    }  
    public function admin_get_item($id=FALSE, $fields='*'){

        $this->db->select($fields)
                ->from('newsletters')       
                ->where('id_Newsletters', $id);  
        
        $query = $this->db->get();
        return $query->row_array();

    }  
    public function admin_update($id=FALSE, $data=array()){

        $this->db->where('id_Newsletters', $id)
                ->update('newsletters', $data); 

    }                      
    public function admin_insert($data=array()){

        $data["id_Newsletters"] = uniqid();
        $data["Active_Newsletters"] = 0;
        $this->db->insert('newsletters', $data); 
        return $data["id_Newsletters"];

    }  
    public function admin_delete($id=FALSE){

        $this->db->where('id_Newsletters', $id);
        $this->db->delete('newsletters'); 

    } 
	

}
?>